<!DOCTYPE html>

<html lang="zh-Hans">
  <head>
    <meta charset="utf-8" />
    <meta name="author" content="rogepi" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="/vue.global.js"></script>
    <title>2-event-with-method</title>
  </head>

  <body>
    <div id="event-with-method">
      <!-- `greet` 是在下面定义的方法名 -->
      <button @click="greet">Greet</button>
    </div>
    <script>
      Vue.createApp({
        data() {
          return {
            name: 'Vue.js',
          };
        },
        methods: {
          greet(event) {
            // `methods` 内部的 `this` 指向当前活动实例
            alert('Hello ' + this.name + '!');
            // `event` 是原生 DOM event
            if (event) {
              alert(event.target.tagName);
            }
          },
        },
      }).mount('#event-with-method');
    </script>
  </body>
</html>
